#include"util.hpp"
#include"db.hpp"
#include"server.hpp"

#define HOST "127.0.0.1"
#define USER "root"
#define PASS ""
#define DB "db98"
#define PORT 3306
void user_table_test()
{
  im::UserTable *ut=new im::UserTable(HOST,USER,PASS,DB,PORT);
  Json::Value user;
  user["username"]="不知道";
  user["nickname"]="呵呵";
  user["password"]="123456";
  user["old_password"]="9000000";
  user["new_password"]="9000000";
  //ut->insert(user);
  //ut->remove(1);
  //ut->update_password(user);
  //ut->update_nickname(user);
  Json::Value root;
  //ut->select_by_id(2,&root);
  ut->select_by_name("王五",&root);
  string body;
  im::JsonUtil::serialize(root,&body);
  cout<<body<<endl;
}
void msg_table_test()
{
  im::MsgTable *mt=new im::MsgTable(HOST,USER,PASS,DB,PORT);
  Json::Value msg;
  msg["uid"]=2;
  msg["msg"]="敲代码好难啊！！";
  //mt->insert(msg);
  Json::Value root;
  mt->select_part(400,&root);
  string body;
  im::JsonUtil::serialize(root,&body);
  cout<<body<<endl;
}
void server_test(int port)
{
  im::Server server(HOST,USER,PASS,DB,PORT);//数据库端口
  server.Start(port);//服务器监听 绑定端口
}
int main()
{
  //user_table_test();
  //msg_table_test();
  server_test(9000);
  return 0;
}
